#include <QApplication>

#include <QDate>
#include <QTime>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSplitter>
#include <QString>
#include <iostream>

#include "mytexteditor.h"

using namespace std;


QString getTodoDateAndTime();


int main(int argc, char *argv[])
{

  QApplication app(argc, argv);




  //GUI 
  
  
  myQTextEdit *editor = new myQTextEdit();
  editor->loadFile();

  QPushButton *loadButton = new QPushButton("Load");
  
  
  //loadFile is a user defined slots
  QObject::connect(loadButton, SIGNAL(clicked()),
                   editor,     SLOT  (loadFile()  ));
  
  QPushButton *saveButton = new QPushButton("Save");
  QObject::connect(saveButton, SIGNAL(clicked()),
                   editor,     SLOT(saveFile()));
  QPushButton *quickButton = new QPushButton("Quit");
  QObject::connect(quickButton, SIGNAL(clicked()), &app, SLOT(quit()));
  
  //button on the right
  QVBoxLayout *vLayout = new QVBoxLayout();
  vLayout->addWidget(loadButton);
  vLayout->addWidget(saveButton);
  vLayout->addWidget(quickButton);  
  vLayout->addStretch();

  //editor on the left
  QHBoxLayout *hLayout = new QHBoxLayout();
  hLayout->addWidget(editor);




  //add the right layout to the left layout
  hLayout->addLayout(vLayout);

  QWidget *window = new QWidget;
  window->setLayout(hLayout);
  window->setWindowTitle(getTodoDateAndTime());
  window->show();
  //splitter.show();
  getTodoDateAndTime();
  
  return app.exec();
}


QString getTodoDateAndTime()
{
  QString result;
  QDate qd = QDate::currentDate();
  int day = qd.day();
  //int week = qd.dayOfWeek();
  int year = qd.year();
  int month = qd.month();

  QString ys = QString::number(year);
  QString ms = QDate::shortMonthName(month);
  //QString ws = QDate::shortDayName(week);
  QString ds = QString::number(day);
  
  cout << day << endl;
  //cout << week<<endl;
  cout << month<< endl;
  cout << ys.toStdString()+ms.toStdString()+ds.toStdString()<<endl;
  //cout << "ws.length="<<ws.length()<<endl;

  QTime ct = QTime::currentTime();
  QString cts = ct.toString("h:m ap"); 
  return ys+"-"+ms+"-"+ds+"   "+cts;
}



